import { DictEntity } from './../../../entities/sys/dict.entity';
import { BaseService } from '@src/service/base/base.service';
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateDictDto } from '@src/controllers/admin/system/dict/dto';

@Injectable()
export class DictService extends BaseService {
  constructor(
    @InjectRepository(DictEntity)
    private readonly dictRepository: Repository<DictEntity>,
  ) {
    super(dictRepository)
  }

  /**
 * 数据唯一性校验
 * @memberof RoleService
 */
  public async checkUnique(name: string): Promise<boolean> {
    const dict = await this.dictRepository.findOne({ name });
    if (dict) {
      throw new HttpException({ error: '当前字典名称已经存在' }, HttpStatus.BAD_REQUEST)
    }
    return true;
  }
}